package com.bxx.controller;

import com.bxx.common.dto.ClassDto;
import com.bxx.common.lang.Result;
import com.bxx.entity.Class;
import com.bxx.service.ClassService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ClassController {

    @Autowired
    ClassService classService;

    /**
     * 所有分类列表
     * @return
     */
    @GetMapping("/class/list")
    public Result list(){
        List<ClassDto> data = classService.getClassInfo();
        return Result.succ(data);
    }

    @GetMapping("/class/nlist")
    public Result normalList(){
        List<Class> list = classService.list();
        return Result.succ(list);
    }

    /**
     * 新增或修改分类
     * @param type
     * @return
     */
    @PostMapping("/class/add")
    @RequiresAuthentication
    public Result addUpdate(@Validated @RequestBody Class type){
        classService.saveOrUpdate(type);
        return Result.succ(null);
    }
}
